<template>
  <div id="formla">
    <el-dialog :title="formulatitle" :close-on-click-modal="false" width="60%" :visible.sync="Formulavisible">
      <div class="formulamain">
        <div class="cont-title">公式因子</div>
        <div class="cont-tags">
          <el-radio-group v-model="dataForm.formulaType" style="margin-bottom: 30px;">
            <el-radio-button v-for="(item, index) in formulaType" :label="item.value" :key="index" @click.native="getradio(item)">{{ item.label }}</el-radio-button>
          </el-radio-group>
        </div>
        <div class="cont-table" v-show="dataForm.formulaType==='3'">
          <my-table :col="col" :data="data" @getcode="getcode">
          </my-table>
        </div>
       <div class="cont-table" v-show="dataForm.formulaType==='2'">
          <my-table :col="col2" :data="data2"  @getcode="getcode">
          </my-table>
        </div>
        <div class="cont-table" v-show="dataForm.formulaType==='1'">
          <my-table :col="col3" :data="data3" @getcode="getcode" >
          </my-table>
        </div>
      <div class="fmain">
        <el-form :model="dataForm" label-width="100px">
          <el-row>
            <el-form-item label="符号选择">
            <div class="con-Symbol">
            <div class="Symbol" v-for="(item,index) in Symbol" :key="index" @click="getSymbol(item)">
              <span>{{item}}</span>
            </div>
            </div>
            </el-form-item>
              <el-row>
        <el-col :span="24">
          <el-form-item label="公式"  prop="">
            <el-input type="textarea" :rows="3" readonly v-model="dataForm.expression"></el-input>
          </el-form-item>
        </el-col>

        <el-col :span="24">
          <el-form-item label="公式说明"  prop="">
            <el-input type="textarea" :rows="3" readonly v-model="dataForm.desc"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
          </el-row>
        </el-form>
      </div>
      </div>
      <span slot="footer" class="dialog-footer" style="text-align: center !important;">
        <el-button type="info" plain @click="FormulaSubmit()">保存</el-button>
        <el-button @click="Formulavisible = false">取消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {getFormula} from "@/api/baseConfig/conditionDivisor";
import insure from "@/api/insure";
import constant from "@/api/constant";
import { formulaTranslate2 } from '@/utils'
export default {
  props: ["formulatitle"],
  data() {
    return {
      formulaType: [
      {label: '住院收据', value: '3'},
      {label: '门诊收据', value: '2'},
      {label: '药房收据', value: '1'},
    ],
      Symbol:insure.fhdm,
      dataForm:{
        formulaType:'3',
        expression:'',
        desc:'',
      },
      Formulavisible: false,
      // 住院数据
      col: insure.Hospital,
      data: [],
      // 门诊数据
      col2: insure.menzhen,
      data2: [],
      // 药房收据(Y)
      col3: insure.YMSJ,
      data3: [],
      // //非医疗收据
      // col4: insure.NOHospital,
      // data4: insure.NOHospitalDATA
    };
  },
  created() {
    let Hospitaldata = JSON.parse(JSON.stringify(insure.Hospitaldata))
    let menzhenTable = JSON.parse(JSON.stringify(insure.menzhenTable))
    let YMSJDATA = JSON.parse(JSON.stringify(insure.YMSJDATA))
    this.data = formulaTranslate2(Hospitaldata, 'id','parentCode')
    this.data2 = formulaTranslate2(menzhenTable, 'id','parentCode')
     this.data3 = formulaTranslate2(YMSJDATA, 'id','parentCode')
    // console.log(this.data,'data');
  },
  methods: {
    getradio(item) {

    },
    FormulaSubmit() {
      this.Formulavisible = false
      this.$emit('getFormulainfo',this.dataForm)
    },
    getSymbol(item) {
      // console.log(item);
    this.dataForm.expression+=item
    this.dataForm.desc+=item
    if (item === 'DEL') {
      this.dataForm.expression = ''
      this.dataForm.desc = ''
    }
    },
    // 获取表格因子
    getcode(data) {
    // console.log(data);
      let param={
        formulaType:this.dataForm.formulaType,
        formulaCode:data
      }
      getFormula(param).then(res=>{
        if (res.data.data && res.data.data.remark) {
          let data = res.data.data
         this.dataForm.expression += data.remark
         this.dataForm.desc += data.formulaName
        }
      })
    }
  },
};
</script>

<style lang="less">
.con-Symbol {
  display: flex;
}
.Symbol {
  width: 50px;
  height: 40px;
  line-height: 40px;
  text-align: center;
  border: 1px solid rgba(247, 101, 101, 1);
  color: rgba(247, 101, 101, 1);
  border-radius: 2px;
  margin-right: 5px;
  cursor: pointer;
  span {
    font-size: 16px;
  }
}
#formla > .el-dialog__wrapper .el-dialog .el-dialog__header {
  border-bottom: 1px solid #efefef;
}
#formla > .el-dialog__wrapper .el-dialog .el-dialog__body {
  padding: 0;
}
.formulamain {
  margin: 0px 50px;
  background-color: #fff;
  div.cont-title {
    height: 50px;
    line-height: 50px;
    font-weight: 900;
    font-size: 16px;
  }
  .cont-tags {
    height: 40px;
    background-color: #f2f2f2;
  }
  .cont-table {
    margin-top: 30px;
  }
 .fmain {
   margin-top: 80px;
 } 
}
</style>